package com.coder4j.controller;

import com.coder4j.service.SControlService;
import com.coder4j.starter.mybatis.BasePage;
import com.coder4j.starter.web.R;
import com.coder4j.vo.MenuData;
import com.coder4j.vo.SControlDetailVO;
import com.coder4j.vo.SControlQuery;
import com.coder4j.vo.SControlVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 任务流程模块
 * @author keller
 * @date 2025-03-18 16:22:15
 */
@Slf4j
@RestController
@RequestMapping("/sControl")
public class SControlController {
    @Resource
    private SControlService service;

    @Resource
    private HttpServletResponse response;

    /**
     * 按ID查询任务流程表
     * @param id SControl.id
     * @return 任务流程表对象
     */
    @GetMapping("/getById")
    public R<SControlVO> getById( Integer id){

        return R.success(service.baseGetVOById(id));
    }

    @GetMapping("/getMenuData")
    public R<List<MenuData>> getMenuData(){
        return R.success(service.getMenuData());
    }


    /**
     * 保存任务流程表
     * 有 id 字段，更新；否则新增
     * @param sControl SControl对象
     * @return SControl对象
     */
    @PostMapping("/save")
    public R save(@RequestBody SControlVO sControl){
        service.baseSaveVO(sControl);
        return R.success();
    }

    /**
     * 查询列表
     * @param query 查询条件
     * @return 数据列表
     */
    @PostMapping("/page")
    public R<BasePage<SControlVO>> getList(@RequestBody SControlQuery query){
        if(query == null){
            query = new SControlQuery();
        }
        return R.success(service.baseQueryVOPage(query));
    }

    /**
     * 删除任务流程表
     * 如果Entity继承了 BaseSoftDeleteEntity，使用逻辑删除；否则，使用物理删除
     * @param id SControl.id
     * @return 删除的数据
     */
    @PostMapping("/deleteById")
    public R deleteById( Integer id){
        service.baseDeleteById(id);
        return R.success();
    }

    @GetMapping("/getTaskId")
    public R getTaskId( Integer id){
        SControlVO sControlVO = service.baseGetVOById(id);
        return R.success(sControlVO.getTaskId());
    }


}
